/*************************************************
filename	: opengl_graphics_interface.h
author		: Stefan lulham
desc		: Contains the graphics opengl interface
*************************************************/
#ifndef D_OPENGL_GRAPHICS_INTERFACE_H
#define D_OPENGL_GRAPHICS_INTERFACE_H

#include "platform.h"

#pragma comment(lib, "glew32.lib")
#pragma comment(lib, "opengl32.lib")
#if defined(DELGE_PLATFORM_WIN32)
#pragma comment(lib, "glu32.lib")
#include <Windows.h>
#endif
//#include <gl\GL.h>
//#include <gl\GLU.h>
#include <lib\GL\glew.h>

#include <modules\graphics\graphics_interface.h>
#include <modules\graphics\opengl\opengl_texture.h>
#include <modules\graphics\opengl\opengl_graphics_context.h>
#include <modules\graphics\opengl\opengl_font.h>
#include <modules\graphics\opengl\opengl_shader.h>
#include <modules\graphics\opengl\opengl_shader_effect.h>

namespace DelGE
{
	namespace Modules
	{
		namespace Graphics
		{
			class OpenGLGraphicsInterface : public GraphicsInterface
			{
			public:
				OpenGLGraphicsInterface();
				~OpenGLGraphicsInterface();

				GraphicsContext* CreateContext(SystemGadget* pGadget);
				#if defined(DELGE_PLATFORM_WIN32)
				GraphicsContext* CreateContext(HWND hWnd);
				#endif

				void Setup2DProjection(int iWidth = -1, int iHeight = -1);
				void SetViewport(int iX, int iY, int iWidth, int iHeight);
				void SetClearColor(int iRed, int iGreen, int iBlue, int iAlpha = 255);
				void SetClearColor(const Color& rColor);
				void SetGlobalColor(int iRed, int iGreen, int iBlue, int iAlpha = 255);
				void SetGlobalColor(const Color& rColor);

				void ClearScreen();
				void Flip();
				void SetVsync(bool bVsync);

				void SetBlendMode(DelGEGraphicsBlendMode eBlendMode);

				Texture* LoadTexture(string sFilepath, 
											 const Color& oMaskColor = DELGE_GRAPHICSCOLOR_NONE, 
											 GraphicsTexture_UVWrapMode eUWrapMode = GraphicsTexture_UVWrapMode_Clamp,
											 GraphicsTexture_UVWrapMode eVWrapMode = GraphicsTexture_UVWrapMode_Clamp);
				Texture* CreateTexture(int iWidth, int iHeight,
											   GraphicsTexture_UVWrapMode eUWrapMode = GraphicsTexture_UVWrapMode_Clamp,
											   GraphicsTexture_UVWrapMode eVWrapMode = GraphicsTexture_UVWrapMode_Clamp);
				
				Font* LoadFont(string sFilepath, int iSize);
				void UnloadFont(Font* pFont);

				void BeginRenderToTexture(Texture* pGraphicsTexture);
				void EndRenderToTexture();

				void DrawRect(float fX, float fY, float fWidth, float fHeight);
				void DrawLine(float fX0, float fY0, float fX1, float fY1);

				void DrawTexture(Texture* pTexture, float fX, float fY, float fWidth = -1, float fHeight = -1);
				void DrawTextureArea(Texture* pTexture, float fX, float fY, float fWidth = -1, float fHeight = -1,
									 int iAreaX = -1, int iAreaY = -1, int iAreaWidth = -1, int iAreaHeight = -1);
				void DrawMesh(Mesh* pMesh, bool bAutoBuild = true);
				void DrawModel(Model* pModel);
				void DrawEntity(Entity* pEntity);
				void DrawCamera(Camera* pCamera);
				void DrawSprite(Sprite* pSprite);
				void DrawText(string sText, float fX, float fY, Font* pFont);

				float TextWidth(string sText, Font* pFont);
				float TextHeight(string sText, Font* pFont);

				void BindTexture(Texture* pTexture);
				void BindShaderEffect(OpenGLShaderEffect* pShaderEffect);

				void SetModelViewMatrix(const Matrix& rMatrix);
				void SetProjectionMatrix(const Matrix& rMatrix);

				void Begin2DRendering();
				void Begin3DRendering();

				void EnableWireframeMode();
				void EnableDepthTesting();
				void DisableWireframeMode();
				void DisableDepthTesting();

				void EnableLighting();
				void DisableLighting();
			};
		}
	}
}

#endif